#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/init.h>
struct timer_list my_timer;
static void my_timer_func(unsigned long p){
     	int i=my_timer.data;
     	printk(KERN_INFO"%d\n", i);
     	my_timer.data = i+1;   
	my_timer.expires = jiffies + HZ; // 延时1s
     	add_timer(&my_timer);
}  
static int irq;  
static char* devname;  

module_param(devname,charp,0644);  
module_param(irq,int,0644);

static irqreturn_t myirq_handler(int irq,void* dev) 
{  
     struct myirq mydev;  
     static int count=1;  
     mydev=*(struct myirq*)dev;  
     printk("key: %d..\n",count);  
     printk("devid:%d ISR is working..\n",mydev.devid);  
     printk("ISR is leaving..\n");  
     count++;  
     return IRQ_HANDLED;  
} 

static int __init fown_init(void)
{
	init_timer(&my_timer); //初始化结构体   
	my_timer.function = my_timer_func; //初始化回调函数   
	my_timer.data = 0; //初始化data字段，这里也可以是一个结构体的指针，从而传递更多的数据   
	my_timer.expires = jiffies + HZ; //延时1s   
	add_timer(&my_timer);  
	if(request_irq(irq,myirq_handler,IRQF_SHARED,devname,&mydev)!=0){
	        printk("%s request IRQ:%d failed..\n",devname,irq);  
	        return -1;  
	}  
	printk("%s rquest IRQ:%d success..\n",devname,irq); 
	printk(KERN_INFO "fown loaded\n");
	return 0;
}
static void __exit fown_exit(void)
{
	 free_irq(irq,&mydev); 
	 del_timer(&my_timer); //清除结构体  
		printk(KERN_INFO "fown exit\n");
}
module_init(fown_init);
module_exit(fown_exit);

